package leaderus.study;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author lihongliang
 *
 */
public class MyInfo implements Cloneable{
	private Set<String> enabledFeature;
    private boolean enabled;
		
	public Set<String> getEnabledFeature() {
		return enabledFeature;
	}

	public void setEnabledFeature(Set<String> enabledFeature) {
		this.enabledFeature = enabledFeature;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public MyInfo(Set<String> enabledFeature, boolean enabled) {
		this.enabledFeature = enabledFeature;
		this.enabled = enabled;
	}
	
	@Override
	public Object clone(){
		MyInfo o=null;
		try {
			o=(MyInfo)super.clone();
		} catch (CloneNotSupportedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		HashSet<String> enableFeatureClone = new HashSet<String>(o.enabledFeature.size());
		Iterator<String> iterator = enabledFeature.iterator();
		while(iterator.hasNext()){
			enableFeatureClone.add(iterator.next());
		}
		o.setEnabledFeature(enableFeatureClone);
		return o;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (enabled ? 1231 : 1237);
		result = prime * result
				+ ((enabledFeature == null) ? 0 : enabledFeature.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MyInfo other = (MyInfo) obj;
		if (enabled != other.enabled)
			return false;
		if (enabledFeature == null) {
			if (other.enabledFeature != null)
				return false;
		} else if (!enabledFeature.equals(other.enabledFeature))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return "MyInfo [enabledFeature=" + enabledFeature + ", enabled="
				+ enabled + "]";
	}
}
